package top.javai.www.service.impl;

import org.springframework.stereotype.Service;
import top.javai.www.dao.TestTableDAO;
import top.javai.www.pojo.TestTable;
import top.javai.www.service.CacheManager;
import top.javai.www.service.TestTableService;

import javax.annotation.Resource;
import java.util.Date;


@Service
public class TestTableServiceimpl implements TestTableService {
    @Resource
    TestTableDAO testTableDAO;
    @Resource
    CacheManager cacheManager;

    /**
     * 村委会详细信息
     * @param tuid
     * @return
     */
    public TestTable selectTestTableMessage(Integer tuid) {
        if (tuid == 0){
            return null;
        }
        TestTable testTable = testTableDAO.selectTestTableMessage(tuid);
        Integer roleId= testTable.getCreateBy();
        String fromRedis = cacheManager.getFromRedis("donation_" + roleId);
        System.out.println(fromRedis);
        return testTable;
    }

    /**
     * 插入村委会信息
     * @return
     */
    @Override
    public int insertTestTableMessage(Integer roleId,String name) {
        TestTable testTable = new TestTable();
        testTable.setDonationLogo(1);
        testTable.setCreateBy(roleId);
        testTable.setCreated(new Date());
        testTable.setUpdated(new Date());
        testTable.setDonationName(name);
        testTable.setStartAge(0);
        testTable.setEndAge(0);
        int i = testTableDAO.insertTestTableMessage(testTable);
        if (i>0){
            cacheManager.set("donation_" + roleId, " "+testTable, 600);
            return 1;
        }
        return 0;
    }
}
